package com.nosnow.gmall.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @类名称：RedisConfig
 * @类描述： 负责在spring容器启动时自动注入
 * @author: bingHeng
 * @Date
 * @Version: 1.0
*/

@Configuration
public class RedisConfig {

    /**读取配置文件中的redis的ip地址*/
    @Value("${spring.redis.host:disabled}")
    private String host;

    /**读取配置文件中的redis的端口号*/
    @Value("${spring.redis.port:0}")
    private int port;

    /**访问redis的多少号数据库*/
    @Value("${spring.redis.database:0}")
    private int database;

    @Bean
    public RedisUtil getRedisUtil() {
        if(host.equals("disabled")) {
            return null;
        }

        RedisUtil redisUtil = new RedisUtil();
        redisUtil.initPool(host, port, database);
        return redisUtil;
    }


}
